
layui.use(['laydate','table','form'],
    function() {
        let table = layui.table;
        let laydate = layui.laydate
        createTable()
///执行一个laydate实例
        laydate.render({
            elem: '#start' //指定元素
        });

//执行一个laydate实例
        laydate.render({
            elem: '#end' //指定元素
        });
// crateTable();
        var form = layui.form;
        form.on('submit(sreach)',function (){
            createTable();
            return false;

        });
//监听工具条
        table.on('tool(leaving)', function(obj) {
            let data = obj.data;
            if (obj.event === 'del') {
                layer.confirm('真的删除行么', function (index) {
                    let result =myAjax('http://localhost/ssm/back/leaving/delete',{id: data.id},'post')
                    if(result.code=='200'){
                        $(obj).parents("tr").remove();
                        layer.msg('已删除!', {icon: 1, time: 1000});
                    }
                    obj.del();
                    layer.close(index);
                    return false;

                    //sessionStorage.setItem("lawyerId", data.id)
                });
            }
        })
    });

function createTable() {

    layui.use(['layer','table'],function () {
        let layer = layui.layer;
        let table = layui.table;
        table.render(
            {
                elem:"#leaving-list",
                url:"http://localhost/ssm/back/leaving/findAll",
                where:{
                    name:$("#name").val(),
                    phone:$("#phone").val(),
                    mail:$("#mail").val(),
                    start:$("#start").val(),
                    end:$("#end").val(),
                    loginName:sessionStorage.getItem("loginName")

                },
                page:true,
                 parseData: function (res) {
                    if(res.data=="notLogin"){
                        window.open("/html/login.html", "_top");
                    }
                    console.log(res)
                    return{
                        "code":0,
                        "msg":"",
                        "total":res.data.list.length,
                        "data":res.data.list,
                        "count":res.data.count
                    };
                },
                cols:[[
                    {field:'id',title:'ID',width:80,sort:true,fixed:'left'},
                    {field:'name',title:'姓名',width:120},
                    {field:'phone',title:'手机',width:100},
                    {field:'mail',title:'邮箱',width:200},
                    {field:'content',title:'内容',width:500},
                    {field:'createTime',title:'留言时间',width:200},
                    {fixed: 'right', width:200, align:'center', toolbar: '#barDemo'}
                ]],

            }
        );






    })


    console.log(2)
}


